use crate::net::constants::MAX_FRAGMENTS_DEFAULT;
use crate::packet::header::AckedPacketHeader;
use crate::packet::SequenceNumber;

#[derive(Clone)]
/// This contains the information required to reassemble fragments.
pub struct ReassemblyData {
    pub sequence: SequenceNumber,
    pub num_fragments_received: u8,
    pub num_fragments_total: u8,
    pub fragments_received: Vec<Vec<u8>>,
    pub acked_header: Option<AckedPacketHeader>,
}

impl ReassemblyData {
    pub fn new(sequence: SequenceNumber, num_fragments_total: u8, max_fragment_count: u8) -> Self {
        Self {
            sequence,
            num_fragments_received: 0,
            num_fragments_total,
            fragments_received: vec![Vec::new(); max_fragment_count as usize],
            acked_header: None,
        }
    }
}

impl Default for ReassemblyData {
    fn default() -> Self {
        Self {
            sequence: 0,
            num_fragments_received: 0,
            num_fragments_total: 0,
            fragments_received: vec![Vec::new(); MAX_FRAGMENTS_DEFAULT as usize],
            acked_header: None,
        }
    }
}
